import { getCategoryFilterAPI } from "@/apis/category";
import { SubCategoryType } from "@/types/category";
import { ref, watchEffect } from "vue";
import { useRoute } from "vue-router";

// SubCategory页面获取面包屑信息hook
export const useSubCategory = function () {
    // 获取路由params参数
    const route = useRoute();

    // 获取面包屑二级分类信息
    const subCategoryData = ref<SubCategoryType>();

    watchEffect(async onCleanup => {
        // 发送请求
        const { response, controller } = getCategoryFilterAPI(route.params.id as string);
        // 设置清理回调方法
        onCleanup(() => controller.abort());
        // 更新二级标题信息
        subCategoryData.value = (await response).data.result;
    });

    return { subCategoryData };
};